package com.czh.springboot04.service.serviceimpl;

import com.czh.springboot04.entity.Appointment;
import com.czh.springboot04.entity.Consult;
import com.czh.springboot04.entity.User;
import com.czh.springboot04.entity.UserMark;
import com.czh.springboot04.mapper.AppointmentMapper;
import com.czh.springboot04.mapper.ConsultMapper;
import com.czh.springboot04.mapper.UserMapper;
import com.czh.springboot04.mapper.UserMarkMapper;
import com.czh.springboot04.service.UserMarkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserMarkServiceImpl implements UserMarkService {

    @Autowired
    UserMarkMapper userMarkMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    ConsultMapper consultMapper;
    @Autowired
    AppointmentMapper appointmentMapper;
    @Override
    public int insertUserMark(UserMark userMark) {
        return userMarkMapper.insertUserMark(userMark);
    }
    @Override
    public int updateUserMarkById(UserMark userMark) {
        return userMarkMapper.updateUserMarkById(userMark);
    }

    @Override
    public UserMark selectUserMarkById(Integer id) {
        return userMarkMapper.selectUserMarkById(id);
    }
    @Override
    public int deleteUserMarkById(Integer id) {
        return userMarkMapper.deleteUserMarkById(id);
    }
    @Override
    public int deleteUserMarkByList(List<Integer> idList) {
        return userMarkMapper.deleteUserMarkByList(idList);
    }

    @Override
    public PageInfo<UserMark> selectUserMarkAll(Integer userId, Integer consultId, Integer appId, Integer markStar, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserMark> list = userMarkMapper.selectUserMarkAll(userId, consultId, appId, markStar);
        for (UserMark userMark : list) {
            User user = userMapper.selectById(userMark.getUserId());
            userMark.setUser(user);
            Consult consult = consultMapper.findConsultById(userMark.getConsultId());
            userMark.setConsult(consult);
            Appointment appointment = appointmentMapper.selectAppointmentById(userMark.getAppId());
            userMark.setAppointment(appointment);
        }
        return new PageInfo<>(list);
    }
    @Override
    public List<UserMark> selectUserMark() {
        return userMarkMapper.selectUserMark();
    }
}